package com.changgou.goods.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Goods;
import com.changgou.goods.service.GoodsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;
import java.util.ArrayList;

/**
 * @program: changgou_parent
 * @author: zhanzhewan
 * @create: 2020-03-23 21:04
 **/

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;



    @GetMapping("/findall")
    public ArrayList<Goods> findAll()
    {

        return goodsService.findAll();
    }

    @PostMapping("/add")
    public Result add(@RequestBody Goods goods){
        goodsService.add(goods);
        return new Result(true, StatusCode.OK,"添加成功");
    }
    
    /**
     * @Description: 这个商品id是数据库表中spu的某一个id 你需要修改的 
     * @Param:  
     * @return: 
     */ 
    @PostMapping("/update/{id}")
    public Result update(@RequestBody Goods goods,@PathVariable String id){
        System.out.println(id);
        goods.getSpu().setId(id);
        goodsService.update(goods);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    @GetMapping("/find/{id}")
    public Goods find(@PathVariable String id){
        Goods goods = goodsService.find(id);
        return goods;
    }


    //商品审核与上下架 根据传入的商品spuID 来决定哪一个spu上架 还是下架 审核通过就可以上架了
    /**
     * @Description:  先审核
     * @Param:
     * @return:
     */
    @GetMapping("/audit/{id}")
    public Result Audit(@PathVariable String id){
        goodsService.Audit(id);
        return new Result(true,StatusCode.OK,"已审核通过");
    }

    @GetMapping("/shangjia/{id}")
    public Result shangjia(@PathVariable String id){
        goodsService.shangjia(id);
        return new Result();
    }
    @GetMapping("/xiajia/{id}")
    public Result xiajia(@PathVariable String id){

        return new Result();
    }



}
